#include common_scripts\utility;
#include maps\mp\_utility;
#include maps\mp\gametypes\_hud_util;
#include z_migliore\utility;
#using_animtree("multiplayer");


init()
{
    if(!level.zCfg_DeveloperMode)
        return;
    
    /// setSlowMotion(<startTimescale>, <endTimescale>, <deltaTime>);
    
    /// precacheShellShock("pain");
    
    /// precacheHeadIcon("");
    /// precacheMinimapIcon("");
    /// precacheStatusIcon("");
    
    /// laseraltviewon
    /// sethintstring
    
    /// getturretowner
    
    /// missile_setflightmodedirect
    /// missile_setflightmodetop
    
    /// setmotiontrackervisible
    /// getmotiontrackervisible
    
    /// getviewmodel
    
    /// getplayerviewheight
    
    /// getnormalizedmovement
    
    /// switchtoweapon
    /// switchtoweaponimmediate
    /// switchtooffhand
    
    /// setspreadoverride
    /// resetspreadoverride
    
    /// canplayerplacesentry
    
    /// getplayerweaponmodel
    /// getplayerknifemodel
    
    /// setplayernamestring
    /// setmapnamestring
    /// setgametypestring
    
    
    
    precacheModel("projectile_m67fraggrenade_bombsquad");
    precacheModel("projectile_semtex_grenade_bombsquad");
    precacheModel("weapon_c4_bombsquad");
    precacheModel("weapon_claymore_bombsquad");
    precacheModel("weapon_light_stick_tactical_bombsquad");
    
    /*test_shader = "minimap_scanlines";
    
    precacheShader(test_shader);
    
    level.zTest_Shader = createServerIcon(test_shader, 64, 64);
    level.zTest_Shader.foreGround = true;
    level.zTest_Shader.hideWhenInMenu = true;
    level.zTest_Shader setPoint("CENTER", "CENTER", 0, -60);*/
    
    level thread onPlayerConnected();
}

onPlayerConnected()
{
    for(;;) {
        level waittill("connected", player);
        
        //player sayAll("title: " + player maps\mp\gametypes\_persistence::statGet("cardTitle"));
        //player sayAll("icon: " + player maps\mp\gametypes\_persistence::statGet("cardIcon"));
        
        player thread onPlayerSpawned();
        
        player thread test_client_dvars();
        //player thread test_showwaypoints();
        
        player notifyOnPlayerCommand("zkey_actionslot_1", "+actionslot 1");
        player notifyOnPlayerCommand("zkey_actionslot_2", "+actionslot 2");
        player notifyOnPlayerCommand("zkey_actionslot_3", "+actionslot 3");
        player notifyOnPlayerCommand("zkey_actionslot_4", "+actionslot 4");
        player notifyOnPlayerCommand("zkey_centerview", "centerview"); // ufo mode
        player notifyOnPlayerCommand("zkey_melee", "+melee");
        player notifyOnPlayerCommand("zkey_mlook", "+mlook"); // ghost mode
        player notifyOnPlayerCommand("zkey_talk", "+talk");
        
        
    }
}

onPlayerSpawned()
{
    self endon("disconnect");
    
    for(;;) {
        self waittill("spawned_player");
        
        self thread position_and_angle();
        self thread ufo_mode();
        self thread ghost_mode();
    }
}

position_and_angle()
{
    self endon("death");
    self endon("disconnect");
    
    for(;;) {
        self waittill("zkey_talk");
        self sayAll("(" + int(self.origin[0]) + ", " + int(self.origin[1]) + ", " + int(self.origin[2]) + ") @ " + int(self.angles[1]) + " deg");
        
        //self maps\mp\killstreaks\_airdrop::refillAmmo();
        //self sayAll(getWeaponClass(self getCurrentWeapon()));
        self sayTeam(self getVelocity());
    }
}

ufo_mode()
{
    self endon("death");
    self endon("disconnect");
    
    for(;;) {
        self waittill("zkey_centerview");
        self allowSpectateTeam("freelook", true);
        self.sessionstate = "spectator";
        self setContents(0);
        self iPrintLnBold("^3UFO ^7Mode: ^2ON");
        
        self waittill("zkey_centerview");
        self.sessionstate = "playing";
        self allowSpectateTeam("freelook", false);
        self setContents(100);
        self iPrintLnBold("^3UFO ^7Mode: ^1OFF");
    }
}

ghost_mode()
{
    self endon("death");
    self endon("disconnect");
    
    if(isDefined(self.Migliore_Ufo))
        self.Migliore_Ufo delete();
    
    if(isDefined(self.Migliore_UfoVector))
        self.Migliore_UfoVector delete();
    
    for(;;) {
        self waittill("zkey_mlook");
        self.Migliore_Ufo = spawn("script_model", self.origin);
        self.Migliore_Ufo setModel("weapon_c4_bombsquad");
        self.Migliore_Ufo enableLinkTo();
        self.Migliore_UfoVector = spawn("script_origin", self.origin);
        self.Migliore_UfoVector linkTo(self, "tag_weapon_right", (600, 0, 0), (0, 0, 0));
        
        self playerLinkToDelta(self.Migliore_Ufo, "tag_origin", 0, 180, 180, 180, 180, false);
        self thread ghost_mode_moving();
        self iPrintLnBold("^3Ghost ^7Mode: ^2ON");
        
        
        self waittill("zkey_mlook");
        self unLink();
        self.Migliore_UfoVector delete();
        self.Migliore_Ufo delete();
        self iPrintLnBold("^3Ghost ^7Mode: ^1OFF");
    }
}

ghost_mode_moving()
{
    self endon("death");
    self endon("disconnect");
    self endon("zkey_centerview");
    
    for(;;) {
        if(self playerADS() > 0.95)
            self.Migliore_Ufo moveTo(self.Migliore_UfoVector.origin, distance(self.Migliore_Ufo.origin, self.Migliore_UfoVector.origin)/1200.0);
        else
            self.Migliore_Ufo moveTo(self.Migliore_Ufo.origin, 0.01);
        
        wait(0.05);
    }
}

test_client_dvars()
{
    //self setClientDvar("cg_drawFPS", "SimpleRanges");
    //self setClientDvar("cg_drawViewpos", "1");
    
    self setClientDvar("cg_drawFPS", "Off");
    self setClientDvar("cg_drawViewpos", "0");
}

